//
//  ICMProxyPreviewView.m
//  ICrEAM
//
//  Created by Cty on 2016/11/10.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMProxyPreviewView.h"
#import "PreviewItemAndComponentView.h"
#import "PreviewBaseItemView.h"
#import "PreviewItemsModel.h"
#import "PreviewCompsModel.h"
#import "ICMProxyActivityModel.h"
#define DisplayWidth      ActualWidth(984)
#define StartLeftDistance      ActualWidth(80)
#define ItemWidth      ActualWidth(260)
#define ItemHeight      ActualWidth(50)
#define titleDistance      ActualWidth(10)

@interface ICMProxyPreviewView()

@property (nonatomic,strong) NSString *repairTypeNamePart;

@property (nonatomic,strong) NSString *repairTypeNameLabour;

@property (nonatomic,strong) NSMutableArray *labourArray;

@property (nonatomic,strong) NSMutableArray *partArray;
@property (nonatomic,strong) NSMutableArray *stationArray;
@end


@implementation ICMProxyPreviewView
-(NSMutableArray *)stationArray{
    if (!_stationArray) {
        _stationArray = [NSMutableArray array];
    }
    return _stationArray;
}
-(NSMutableArray *)labourArray{
    if (!_labourArray) {
        _labourArray = [NSMutableArray array];
    }
    return _labourArray;
}

-(NSMutableArray *)partArray{
    if (!_partArray) {
        _partArray = [NSMutableArray array];
    }
    return _partArray;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        
    }
    return self;
}

#pragma mark 布局赋值
- (void)setUpChildView{
    CGFloat left=ActualWidth(20);
    CGFloat top=20;
    if (!self.isFinishCheckPush) {
        UILabel *label  = [[UILabel alloc] initWithFrame:CGRectMake(left,ActualWidth(20), DisplayWidth, ActualHeight(20))];
        label.textAlignment = NSTextAlignmentLeft;
        label.textColor = TitleColor_Dark;
        label.font = NaviFont;
        label.text = @"委托书车主车辆信息";
        //1.车辆信息块
        //第一行分割线
        UIView *firstLine = [[UIView alloc] initWithFrame:CGRectMake(label.x, label.bottomEdge+ActualHeight(20), DisplayWidth+ActualWidth(20), 1)];
        
        firstLine.backgroundColor = BackgroundColor_Gray;
        
        
        //车牌号
        PreviewBaseItemView *carNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, firstLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                       @"车牌号" andSubTitle:self.proxyBasicInfoModel.LICENSE];
        //VIN
        PreviewBaseItemView *vinNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(carNum.rightEdge, firstLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                       @"VIN" andSubTitle:self.proxyBasicInfoModel.VIN];
        
        //购车发票日期
        PreviewBaseItemView *invoicesDate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(vinNum.rightEdge, firstLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                             @"购车发票日期" andSubTitle:StrIsZero_gdm(self.proxyBasicInfoModel.SALES_DATE)?@"":[ICrEAMTool getDateWithTimeInterval:self.proxyBasicInfoModel.SALES_DATE]];
        
        
        //行驶里程
        PreviewBaseItemView *mileage = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(invoicesDate.rightEdge, firstLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                        @"行驶里程" andSubTitle:self.proxyBasicInfoModel.IN_MILEAGE];
        //车型
        PreviewBaseItemView *carType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, carNum.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                        @"车型" andSubTitle:self.proxyBasicInfoModel.MODEL_NAME];

        
        [self addSubview:firstLine];
        [self addSubview:label];
        [self addSubview:carNum];
        [self addSubview:vinNum];
        [self addSubview:invoicesDate];
        [self addSubview:mileage];
        [self addSubview:carType];
        
        //使用性质
        PreviewBaseItemView *useType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(carType.rightEdge, carNum.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                        @"使用性质" andSubTitle:[ICrEAMTool getCodeModelForCode:self.proxyBasicInfoModel.USE_KIND].desc];
        
        [self addSubview:useType];
        
        //三包凭证标识
        PreviewBaseItemView *isThreeGuarantee = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(useType.rightEdge, carNum.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                                 @"三包凭证标识" andSubTitle:[ICrEAMTool getCodeModelForCode:self.proxyBasicInfoModel.TRACE_TAG_DESC].desc];
        
        
        [self addSubview:isThreeGuarantee];
        
        //上次进厂日期
        PreviewBaseItemView *lastEntryDate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(isThreeGuarantee.rightEdge, carNum.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                              @"上次进厂日期" andSubTitle:StrIsZero_gdm(self.proxyBasicInfoModel.LAST_MAINTAIN_DATE)?@"":[ICrEAMTool getDateWithTimeInterval:self.proxyBasicInfoModel.LAST_MAINTAIN_DATE]];
        
        [self addSubview:lastEntryDate];
        
        //进口车标识
        PreviewBaseItemView *isImportCar = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, lastEntryDate.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                            @"进口车标识" andSubTitle:(!self.proxyBasicInfoModel.IS_FBU || [self.proxyBasicInfoModel.IS_FBU isEqualToString:@""])?@"":[ICrEAMTool getCodeModelForCode:self.proxyBasicInfoModel.IS_FBU].desc];
        
        [self addSubview:isImportCar];
        
        
        //车牌图片
        UIImage *image = [UIImage imageNamed:Appointment_Car];
        
        UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
        
        imageView.frame =CGRectMake(ActualHeight(20), firstLine.bottomEdge+(isImportCar.bottomEdge-firstLine.bottomEdge)/2-ActualHeight(15), ActualWidth(30), ActualHeight(30));
        
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        
        [self addSubview:imageView];
        //2.车主信息块
        //第二行分割线
        UIView *secondLine = [[UIView alloc] initWithFrame:CGRectMake(isImportCar.x, isImportCar.bottomEdge+ActualHeight(20), ActualWidth(1024)-isImportCar.x, 1)];
        
        secondLine.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:secondLine];
        
        
        
        //车主姓名
        PreviewBaseItemView *ownerName = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, secondLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                          @"车主姓名" andSubTitle:self.proxyBasicInfoModel.OWNER_NAME];
        
        [self addSubview:ownerName];
        //车主手机
        PreviewBaseItemView *ownerPhone = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(ownerName.rightEdge, secondLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                           @"车主手机" andSubTitle:self.proxyBasicInfoModel.MOBILE];
        [self addSubview:ownerPhone];
        
        //预约人姓名
        PreviewBaseItemView *appointedName = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(ownerPhone.rightEdge, secondLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                              @"送修人姓名" andSubTitle:self.proxyBasicInfoModel.DELIVERER];
        [self addSubview:appointedName];
        //预约人手机
        PreviewBaseItemView *appointedPhone = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(appointedName.rightEdge, secondLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                               @"送修人手机" andSubTitle:self.proxyBasicInfoModel.DELIVERER_MOBILE];
        [self addSubview:appointedPhone];
        //车主性质
        PreviewBaseItemView *ownerType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, appointedPhone.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                          @"车主性质" andSubTitle:[ICrEAMTool getCodeModelForCode:self.proxyBasicInfoModel.OWNER_PROPERTY].desc];
        
        [self addSubview:ownerType];
        
        //3.会员信息
        //第三行分割线
        UIView *thirdLine = [[UIView alloc] initWithFrame:CGRectMake(ownerType.x, ownerType.bottomEdge+ActualHeight(20), ActualWidth(1024)-carType.x, 1)];
        
        thirdLine.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:thirdLine];
        
        
        //斯柯达
        //会员编号
        PreviewBaseItemView *MemberNoView = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                          @"会员编号" andSubTitle:self.proxyBasicInfoModel.MEMBER_NO];
        if(![ICrEAMTool isVW])
        {
            [self addSubview:MemberNoView];
        }
        
        //大众一家
        PreviewBaseItemView *vmOneHome = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                          @"大众一家" andSubTitle:self.proxyBasicInfoModel.HQ_VW_CARD_ID];
        
        if([ICrEAMTool isVW])
        {
            [self addSubview:vmOneHome];
        }
        
        //实物卡号
        PreviewBaseItemView *cardNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(vmOneHome.rightEdge, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                        @"实物卡号" andSubTitle:self.proxyBasicInfoModel.BAR_CODE];
        if([ICrEAMTool isVW])
        {
            [self addSubview:cardNum];
        }
        
        //经销商会员
        PreviewBaseItemView *agencyMember = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(cardNum.rightEdge, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                             @"经销商会员" andSubTitle:self.proxyBasicInfoModel.MEMBER_NO];
        if([ICrEAMTool isVW])
        {
            [self addSubview:agencyMember];
        }
        
        //会员积分
        PreviewBaseItemView *memberCount = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(agencyMember.rightEdge, thirdLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                            @"会员积分" andSubTitle:self.proxyBasicInfoModel.TTL_CONSUME_CREDIT];
        if([ICrEAMTool isVW])
        {
            [self addSubview:memberCount];
        }
        
        //车主图片
        //车牌信息
        UIImage *imageOwner = [UIImage imageNamed:Appointment_CarOwner];
        // 当没有设置imageView的frame时
        // 图片控件所占的区域与加载的图片大小保持一致
        UIImageView *imageViewOwner = [[UIImageView alloc]initWithImage:imageOwner];
        
        imageViewOwner.frame =CGRectMake(ActualHeight(20), secondLine.bottomEdge+(memberCount.bottomEdge-secondLine.bottomEdge)/2-ActualHeight(15), ActualWidth(30), ActualHeight(30));
        
        //设置图片的显示模式
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        
        [self addSubview:imageViewOwner];
        
        
        //分割块
        UIView *sperator1 = [[UIView alloc] initWithFrame:CGRectMake(0, memberCount.bottomEdge+ActualHeight(20), ScreenWidth, 1)];
        
        sperator1.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:sperator1];
        
        
        UIView *block1 = [[UIView alloc] initWithFrame:CGRectMake(0, sperator1.bottomEdge, ScreenWidth, 13)];
        
        block1.backgroundColor = Color(0xf1f3f3);
        
        [self addSubview:block1];
        
        UIView *sperator2 = [[UIView alloc] initWithFrame:CGRectMake(0, block1.bottomEdge, ScreenWidth, 1)];
        
        sperator2.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:sperator2];
        
        /***********************/
        //委托书单据信息
        UILabel *label3  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20),sperator2.bottomEdge+ ActualWidth(20), DisplayWidth, ActualHeight(20))];
        label3.textAlignment = NSTextAlignmentLeft;
        label3.textColor = TitleColor_Dark;
        label3.font = NaviFont;
        label3.text = @"委托书单据信息";
        
        [self addSubview:label3];
        //1.委托书信息
        //分割线
        UIView *fourthLine = [[UIView alloc] initWithFrame:CGRectMake(label3.x, label3.bottomEdge+ActualHeight(20), DisplayWidth+ActualWidth(20), 1)];
        
        fourthLine.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:fourthLine];
        
        //维修类型
        PreviewBaseItemView *repireType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, fourthLine.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                           @"维修类型" andSubTitle:self.proxyBasicInfoModel.RO_REPAIR_TYPE_NAME];
        
        [self addSubview:repireType];
        
        //预计交车时间
        PreviewBaseItemView *estimateCompletedTime = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(repireType.rightEdge, fourthLine.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                                      @"预计交车时间" andSubTitle:StrIsZero_gdm(self.proxyBasicInfoModel.END_TIME_SUPPOSED)?@"":[ICrEAMTool getDateHourAndMinWithTimeInterval:self.proxyBasicInfoModel.END_TIME_SUPPOSED]];
        
        [self addSubview:estimateCompletedTime];
        
        //旧件处理
        PreviewBaseItemView *oldPartResolve = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(estimateCompletedTime.rightEdge, fourthLine.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                               @"旧件处理" andSubTitle:self.proxyBasicInfoModel.OLD_PART_PROCESS_DESC];
        
        [self addSubview:oldPartResolve];
        
        //诚信经营
        PreviewBaseItemView *honestyOperate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(oldPartResolve.rightEdge, fourthLine.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                               @"诚信经营" andSubTitle:self.proxyBasicInfoModel.HONEST_BUSINESS_DESC];
        
        [self addSubview:honestyOperate];
        honestyOperate.hidden = YES;
        
        
        //预约单号
        PreviewBaseItemView *appointmentNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, honestyOperate.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                               @"预约单号" andSubTitle:self.proxyBasicInfoModel.BOOKING_ORDER_NO];
        
        [self addSubview:appointmentNum];
        
        //预约开单时间
        PreviewBaseItemView *estimateCreatTime = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(appointmentNum.rightEdge, honestyOperate.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                                  @"预约开单时间" andSubTitle:StrIsZero_gdm(self.proxyBasicInfoModel.BOOKING_COME_TIME)?@"":[ICrEAMTool getDateWithTimeInterval:self.proxyBasicInfoModel.BOOKING_COME_TIME]];
        
        [self addSubview:estimateCreatTime];
        
        //接车单号
        PreviewBaseItemView *getCarNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(estimateCreatTime.rightEdge, honestyOperate.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                          @"接车单号" andSubTitle:self.proxyBasicInfoModel.RECEPTION_NO];
        
        [self addSubview:getCarNum];
        
        //接车时间
        PreviewBaseItemView *getCarTime = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(getCarNum.rightEdge, honestyOperate.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                           @"接车时间" andSubTitle:StrIsZero_gdm(self.proxyBasicInfoModel.RECEPTION_DATE)?@"":[ICrEAMTool getDateWithTimeInterval:self.proxyBasicInfoModel.RECEPTION_DATE]];
        
        [self addSubview:getCarTime];
        
        
        //委托书号
        PreviewBaseItemView *proxyNum = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, getCarTime.bottomEdge+titleDistance, ItemWidth, ItemHeight) andTitle:
                                         @"委托书号" andSubTitle:self.proxyBasicInfoModel.RO_NO];
        
        [self addSubview:proxyNum];
        
        //接待服务顾问
        PreviewBaseItemView *assistant = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(proxyNum.rightEdge, getCarTime.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                          @"接待服务顾问" andSubTitle:self.proxyBasicInfoModel.EMPLOYEE_NAME];
        
        [self addSubview:assistant];
        
        
        //凭证类型
        PreviewBaseItemView *certType = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(assistant.rightEdge, getCarTime.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                         @"凭证类型" andSubTitle:[self.proxyBasicInfoModel.RO_REPAIR_TYPE_NAME isEqualToString:@"质量担保保养"]?@"新首保卡":[ICrEAMTool getCodeModelForCode:self.proxyBasicInfoModel.VOUCHER_TYPE].desc];
        [self addSubview:certType];
        certType.hidden = YES;
        
        //校验码
        PreviewBaseItemView *vertifiCode = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(certType.rightEdge, getCarTime.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                            @"校验码" andSubTitle:self.proxyBasicInfoModel.CHECK_CODE];
        
        [self addSubview:vertifiCode];
        vertifiCode.hidden = YES;
        
        //车间标识
        PreviewBaseItemView *workShop = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, vertifiCode.bottomEdge +titleDistance, ItemWidth, ItemHeight) andTitle:
                                         @"车间标识" andSubTitle:self.proxyBasicInfoModel.IS_EWS_SUCCESS_DESC];
        
        [self addSubview:workShop];
        workShop.hidden = YES;
        
        
        
        //分割线
        UIView *FifthLine = [[UIView alloc] initWithFrame:CGRectMake(isImportCar.x, workShop.bottomEdge+ActualHeight(20), ActualWidth(1024)-isImportCar.x, 1)];
        
        FifthLine.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:FifthLine];
        
        
        
        //用户故障描述
        PreviewBaseItemView *faultDescribe = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, FifthLine.bottomEdge+titleDistance, (ScreenWidth-StartLeftDistance)/2-5, ActualHeight(100)) andTitle:
                                              @"用户故障描述" andSubTitle:self.proxyBasicInfoModel.CUSTOMER_DESC andType:0];
        
        [self addSubview:faultDescribe];
        //检查前预判
        PreviewBaseItemView *prognosis = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance + (ScreenWidth-StartLeftDistance)/2 + 5, FifthLine.bottomEdge+titleDistance, (ScreenWidth-StartLeftDistance)/2-5, ActualHeight(100)) andTitle:
                                          @"检查前预判" andSubTitle:self.proxyBasicInfoModel.PRE_JUDGE andType:0];
        [self addSubview:prognosis];
        
        //故障检查报告
        PreviewBaseItemView *faultCheckReport = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, prognosis.bottomEdge+titleDistance, (ScreenWidth-StartLeftDistance)/2-5, ActualHeight(100)) andTitle:
                                                 @"故障检查报告" andSubTitle:self.proxyBasicInfoModel.RO_TROUBLE_DESC andType:0];
        [self addSubview:faultCheckReport];
        
        //备注
        PreviewBaseItemView *comment = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance + (ScreenWidth-StartLeftDistance)/2 + 5, prognosis.bottomEdge+titleDistance, (ScreenWidth-StartLeftDistance)/2-5, ActualHeight(100)) andTitle:
                                        @"备注" andSubTitle:self.proxyBasicInfoModel.REMARK andType:0];
        [self addSubview:comment];
        
        
        
        
        /**************************/
        
        
        //分割块
        UIView *speratorProxy1 = [[UIView alloc] initWithFrame:CGRectMake(0, comment.bottomEdge+ActualHeight(20), ScreenWidth, 1)];
        
        speratorProxy1.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:speratorProxy1];
        
        
        UIView *blockProxy1 = [[UIView alloc] initWithFrame:CGRectMake(0, speratorProxy1.bottomEdge, ScreenWidth, 13)];
        
        blockProxy1.backgroundColor = Color(0xf1f3f3);
        
        [self addSubview:blockProxy1];
        
        UIView *speratorProxy2 = [[UIView alloc] initWithFrame:CGRectMake(0, blockProxy1.bottomEdge, ScreenWidth, 1)];
        
        speratorProxy2.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:speratorProxy2];
        
        
        //车牌图片
        UIImage *imageProxy = [UIImage imageNamed:GetCar_Proxy];
        
        UIImageView *imageViewProxy = [[UIImageView alloc]initWithImage:imageProxy];
        
        imageViewProxy.frame =CGRectMake(ActualHeight(20), fourthLine.bottomEdge+(comment.bottomEdge-fourthLine.bottomEdge)/2-ActualHeight(15), ActualWidth(30), ActualHeight(30));
        
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        
        [self addSubview:imageViewProxy];
        top= speratorProxy2.bottomEdge+ActualHeight(20);
        
    }
    
    /*---------*/
    
    //6.所选活动
    //所选活动title
    UILabel *selectedActivity  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20),top, DisplayWidth, ActualHeight(20))];
    selectedActivity.textAlignment = NSTextAlignmentLeft;
    selectedActivity.textColor = [UIColor colorWithHex:0x000000];
    
    selectedActivity.textColor = TitleColor_Dark;
    selectedActivity.font = NaviFont;
    selectedActivity.text = @"所选活动";
    [self addSubview:selectedActivity];
    
    //第6行分割线
    UIView *sixthLine = [[UIView alloc] initWithFrame:CGRectMake(left, selectedActivity.bottomEdge+ActualHeight(20), ActualWidth(1024)-StartLeftDistance, 1)];
    
    sixthLine.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sixthLine];
    self.activityFrame = sixthLine.frame;
    for (int i=0; i<self.activityModels.count; i++) {
        //活动名称
        ICMProxyActivityViewModel *model = self.activityModels[i];
        
        UILabel *activityName  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(60),self.activityFrame.origin.y+self.activityFrame.size.height+ActualWidth(40),ActualWidth(600),  ActualHeight(20))];
        activityName.textAlignment = NSTextAlignmentLeft;
        activityName.text = model.title?:@"";
        activityName.textColor = ContentTextColor_Gray;
        [self addSubview:activityName];
        
        //活动代码
        UILabel *activityCode  = [[UILabel alloc] initWithFrame:CGRectMake(activityName.rightEdge,self.activityFrame.origin.y+self.activityFrame.size.height+ActualWidth(40),ActualWidth(600),  ActualHeight(20))];
        activityCode.textAlignment = NSTextAlignmentLeft;
        activityCode.text = model.subTitle?:@"";
        activityCode.textColor = ContentTextColor_Gray;
        [self addSubview:activityCode];
        
        //活动分割线
        UIView *activityLine = [[UIView alloc] initWithFrame:CGRectMake(left, activityCode.bottomEdge+ActualHeight(40), ActualWidth(1024)-StartLeftDistance, 1)];
        
        activityLine.backgroundColor = BackgroundColor_Gray;
        
        [self addSubview:activityLine];
        
       // NSArray *activityItems = model.allActivityModel.TT_ACTIVITY_LABOUR;
        
        //NSArray *activityComps = model.allActivityModel.TT_ACTIVITY_PART;
        
       // PreviewItemAndComponentView *itemAndComponentActivityViewCare = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, activityLine.bottomEdge-ActualHeight(40), ScreenWidth, ActualHeight(80)*(activityItems.count+activityComps.count)+ActualHeight(230)) andItems:activityItems andComps:activityComps andType:@"活动"];
        
        //[self addSubview:itemAndComponentActivityViewCare];
        self.activityFrame = activityLine.frame;
    }
    
    
    
    //分割块
    UIView *sperator7 = [[UIView alloc] initWithFrame:CGRectMake(0, self.activityFrame.origin.y+self.activityFrame.size.height+ActualHeight(35), ScreenWidth, 1)];
    
    sperator7.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator7];
    
    
    UIView *block4 = [[UIView alloc] initWithFrame:CGRectMake(0, sperator7.bottomEdge, ScreenWidth, 13)];
    
    block4.backgroundColor = Color(0xf1f3f3);
    
    [self addSubview:block4];
    
    UIView *sperator8 = [[UIView alloc] initWithFrame:CGRectMake(0, block4.bottomEdge, ScreenWidth, 1)];
    
    sperator8.backgroundColor = BackgroundColor_Gray;
    
    [self addSubview:sperator8];
    
    
    
    //7.项目和零件
    //项目和零件title
    UILabel *projectTitle  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(20), sperator8.bottomEdge+ActualHeight(30), DisplayWidth, ActualHeight(20))];
    projectTitle.textAlignment = NSTextAlignmentLeft;
    projectTitle.text = @"项目和零件";
    projectTitle.textColor = TitleColor_Dark;
    projectTitle.font = NaviFont;
    [self addSubview:projectTitle];
    
    
    // 合计
    UILabel *total  = [[UILabel alloc] initWithFrame:CGRectMake(ActualWidth(35), projectTitle.bottomEdge+ActualHeight(30), DisplayWidth, ActualHeight(35))];
    total.textAlignment = NSTextAlignmentLeft;
    total.textColor = TitleColor_Dark;
    total.text = @"    合计";
    total.backgroundColor = Color(0xf0f0f0);
    [self addSubview:total];
    
    
    //工时单价
    PreviewBaseItemView *pricePerH = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                      @"工时单价" andSubTitle:self.proxyBasicInfoModel.LABOUR_PRICE];
    pricePerH.hidden = YES;
    [self addSubview:pricePerH];
    
    //工时费
    PreviewBaseItemView *workPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(pricePerH.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                      @"工时费(折前)" andSubTitle:self.proxyBasicInfoModel.LABOUR_AMOUNT];
    
    [self addSubview:workPrice];
    
    //材料费
    PreviewBaseItemView *materialPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(workPrice.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                          @"材料费(折前)" andSubTitle:self.proxyBasicInfoModel.REPAIR_PART_AMOUNT];
    
    [self addSubview:materialPrice];
    
    //总金额
    PreviewBaseItemView *totalPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(materialPrice.rightEdge, total.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                       @"总金额(折前)" andSubTitle:[NSString stringWithFormat:@"%.2f",[self.proxyBasicInfoModel.LABOUR_TOTAL_AMOUNT doubleValue]]];
    
    [self addSubview:totalPrice];
    
    //工时折旧率
    PreviewBaseItemView *workDesRate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(StartLeftDistance+ItemWidth, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                        @"工时折让金额" andSubTitle:self.proxyBasicInfoModel.LABOUR_DISCOUNT_AMOUNT];
    
    [self addSubview:workDesRate];
    
    //材料折旧率
    PreviewBaseItemView *materialDesRate = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(workDesRate.rightEdge, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                            @"材料折让金额" andSubTitle:self.proxyBasicInfoModel.PART_DISCOUNT_AMOUNT];
    
    [self addSubview:materialDesRate];
    //折后总金额
    PreviewBaseItemView *afterPrice = [[PreviewBaseItemView alloc]initWithFrame:CGRectMake(materialDesRate.rightEdge, totalPrice.bottomEdge+ActualHeight(30), ItemWidth, ItemHeight) andTitle:
                                       @"总金额(折后)" andSubTitle:[NSString stringWithFormat:@"%.2f",[self.proxyBasicInfoModel.REAL_TOTAL_AMOUNT doubleValue]]];
    
    [self addSubview:afterPrice];
    
    self.endFrame = afterPrice.frame;
    
    // 排序
    NSMutableArray *labourArrayNew = [NSMutableArray new];
    for (ICMRepairMaintenanceModel *model in self.repairMaintenancesModel.TT_RO_LABOUR) {
        //重新赋值工时单价
//        model.LABOUR_PRICE = self.proxyBasicInfoModel.LABOUR_PRICE;
        if (StrIsZero_gdm(model.REPAIR_TYPE_NAME)) {
            return;
        }
        if (self.repairTypeNameLabour){
            if ([self.repairTypeNameLabour isEqualToString:model.REPAIR_TYPE_NAME]){
                [labourArrayNew addObject:model];
                if ([self.repairMaintenancesModel.TT_RO_LABOUR indexOfObject:model] == (self.repairMaintenancesModel.TT_RO_LABOUR.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                    [self.labourArray addObject:newArray];
                }
            }else{
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                [self.labourArray addObject:newArray];
                [labourArrayNew removeAllObjects];
                self.repairTypeNameLabour = model.REPAIR_TYPE_NAME;
                [labourArrayNew addObject:model];
                if ([self.repairMaintenancesModel.TT_RO_LABOUR indexOfObject:model] == (self.repairMaintenancesModel.TT_RO_LABOUR.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                    [self.labourArray addObject:newArray];
                }
            }
        }else{
            [labourArrayNew addObject:model];
            self.repairTypeNameLabour = model.REPAIR_TYPE_NAME;
            if ([self.repairMaintenancesModel.TT_RO_LABOUR indexOfObject:model] == (self.repairMaintenancesModel.TT_RO_LABOUR.count-1)) {
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:labourArrayNew];
                [self.labourArray addObject:newArray];
            }
        }
    }
    
    NSMutableArray *partArray = [NSMutableArray array];
    for (ICMRepairPartsModel *model in self.repairPartsArrayModel.TT_RO_REPAIR_PART) {
        if (StrIsZero_gdm(model.REPAIR_TYPE_NAME)) {
            return;
        }
        if (self.repairTypeNamePart) {
            if ([self.repairTypeNamePart isEqualToString:model.REPAIR_TYPE_NAME]) {
                [partArray addObject:model];
                if ([self.repairPartsArrayModel.TT_RO_REPAIR_PART indexOfObject:model] == (self.repairPartsArrayModel.TT_RO_REPAIR_PART.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                    [self.partArray addObject:newArray];
                }
            }else{
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                [self.partArray addObject:newArray];
                [partArray removeAllObjects];
                self.repairTypeNamePart = model.REPAIR_TYPE_NAME;
                [partArray addObject:model];
                if ([self.repairPartsArrayModel.TT_RO_REPAIR_PART indexOfObject:model] == (self.repairPartsArrayModel.TT_RO_REPAIR_PART.count-1)) {
                    NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                    [self.partArray addObject:newArray];
                }
            }
        }else{
            [partArray addObject:model];
            self.repairTypeNamePart = model.REPAIR_TYPE_NAME;
            if ([self.repairPartsArrayModel.TT_RO_REPAIR_PART indexOfObject:model] == (self.repairPartsArrayModel.TT_RO_REPAIR_PART.count-1)) {
                NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:partArray];
                [self.partArray addObject:newArray];
            }
        }
    }
    
    
    //8.底部 一般维修、常规保养
    //项目零件展示
    
    
    if(self.labourArray && self.labourArray.count > 0){
        for (int i = 0 ; i < self.labourArray.count; i++) {
            NSMutableArray *arrayItems = self.labourArray[i];
            ICMRepairMaintenanceModel *maintenanceModel = arrayItems[0];
            
            NSString *typeName = maintenanceModel.REPAIR_TYPE_NAME;
            NSMutableArray *arrayComps = [NSMutableArray array];
            for (NSMutableArray *array in self.partArray) {
                ICMRepairPartsModel *partsModel = array[0];
                if ([partsModel.REPAIR_TYPE_NAME isEqualToString:typeName]) {
                    arrayComps = array;
                }
            }
            
            
//            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(120)*(arrayItems.count+arrayComps.count+[ICMStationModel mj_objectArrayWithKeyValuesArray:_stationsArrayModel].count)+ActualHeight(150)) andItems:arrayItems andComps:arrayComps andStations:stationArray andType:[NSString stringWithFormat:@"   %@",typeName]];
            
        PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:[NSString stringWithFormat:@"   %@",typeName]];
            [self addSubview:itemAndComponentViewFix];
            self.endFrame = itemAndComponentViewFix.frame;
            
        }
    }
    else{
        
        for (int i = 0 ; i < self.partArray.count; i++) {
            NSMutableArray *arrayComps = self.partArray[i];
            ICMRepairPartsModel *partsModel = arrayComps[0];
            NSString *typeName = partsModel.REPAIR_TYPE_NAME;
            NSMutableArray *arrayItems = [NSMutableArray array];
           
            for (NSMutableArray *array in self.labourArray) {
                ICMRepairMaintenanceModel *maintenanceModel = array[0];
                if ([maintenanceModel.REPAIR_TYPE_NAME isEqualToString:typeName]) {
                    arrayItems = array;
                }
            }
//            PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(120)*(arrayItems.count+arrayComps.count+stationArray.count)+ActualHeight(150)) andItems:arrayItems andComps:arrayComps andStations:stationArray andType:[NSString stringWithFormat:@"   %@",typeName]];
        PreviewItemAndComponentView *itemAndComponentViewFix = [PreviewItemAndComponentView creatWithFrame:CGRectMake(0, self.endFrame.origin.y+self.endFrame.size.height+ActualHeight(10), ScreenWidth, ActualHeight(80)*(arrayItems.count+arrayComps.count)+ActualHeight(280)) andItems:arrayItems andComps:arrayComps andType:[NSString stringWithFormat:@"   %@",typeName]];
            [self addSubview:itemAndComponentViewFix];
            self.endFrame = itemAndComponentViewFix.frame;
            
        }
    }
    

}
@end
